<%@ page import="com.ws.haungjia.utils.Res" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>用户管理</title>

	<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
	<%--  rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">--%>
	<script src="${pageContext.request.contextPath}/bootstrap/js/jquery-2.1.0.min.js"></script>
	<script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>

	<style>
		.avatar-img {
			width: 40px;
			height: 40px;
			border-radius: 50%;
			object-fit: cover;
		}
		.search-container {
			background-color: #f8f9fa;
			padding: 15px;
			border-radius: 5px;
			margin-bottom: 20px;
		}
		.table-container {
			background-color: white;
			border-radius: 5px;
			box-shadow: 0 0 10px rgba(0,0,0,0.05);
		}
		.password-cell {
			font-family: monospace;
			letter-spacing: 1px;
			color: #666;
		}
		.operation-cell .btn {
			padding: 3px 8px;
			font-size: 14px;
		}
	</style>
</head>
<body>
<div class="container-fluid py-3">
	<h2 class="mb-3">用户管理</h2>

	<!-- 查询区域 -->
	<div class="search-container">
		<form class="row g-2" action="${pageContext.request.contextPath}/huser/sousuo" method="post">
			<div class="col-md-3">
				<label for="username" class="form-label">用户名</label>
				<input type="text" class="form-control" id="username" name="mohu" placeholder="请输入用户名">
				<input type="submit" value="搜索">
			</div>
			<div class="col-md-3 align-self-end">
<%--				<form action="${pageContext.request.contextPath}/huser/sousuo" method="post">--%>
<%--					<input type="text" name="mouhu" id="searchInput" value="${huixian.mouhu}" placeholder="搜索后台用户名">--%>
<%--					<a href="${pageContext.request.contextPath}/houyonghuguanli/cha" class="btn-edit">清除</a>--%>
<%--				</form>--%>
				<button type="reset" class="btn btn-secondary ms-2">清空</button>
				<button type="submit" class="btn btn-primary">
					<a href="${ pageContext.request.contextPath}/huser/addyemian" style="color: white; text-decoration: none;">增加</a>
				</button>
			</div>
		</form>
	</div>

	<!-- 用户列表 -->
	<div class="table-container">
		<table class="table table-hover">
			<thead>
			<tr>
				<th>编号</th>
				<th>头像</th>
				<th>用户名</th>
				<th>注册时间</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			<c:forEach items="${pageInfo.list}" var="user">
				<tr>
					<td>${user.hid}</td>
					<td><img src="<%=Res.fileUri%>${user.htouxiang}" width="100px" height="100px"></td>
					<td>${user.hname}</td>
					<td> <fmt:formatDate value="${user.hshijian}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
						<%--          <td>${user.zhuceshijian}</td>--%>
					<td class="operation-cell">
						<button class="btn btn-sm btn-warning"><a href="${pageContext.request.contextPath}/huser/huixian?id=${user.hid}" style="color: white; text-decoration: none;">修改</a></button>
						<button class="btn btn-sm btn-danger ms-1"><a href="${pageContext.request.contextPath}/huser/shan?id=${user.hid}" style="color: white; text-decoration: none;">删除</a> </button>
						<button class="btn btn-sm btn-danger ms-1"><a href="${pageContext.request.contextPath}/huser/chongzhi?id=${user.hid}&mima=88888888 " style="color: white; text-decoration: none;">重置为八个八</a> </button>
					</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
		<div class="pagination-container">
			<c:set var="startPage" value="1" />
			<c:set var="endPage" value="10" />
			<c:choose>
				<c:when test="${pageInfo.pageNum <= 5}">
					<c:set var="endPage" value="${pageInfo.pages < 10 ? pageInfo.pages : 10}" />
				</c:when>
				<c:when test="${pageInfo.pageNum > 5 && pageInfo.pageNum <= pageInfo.pages - 5}">
					<c:set var="startPage" value="${pageInfo.pageNum - 4}" />
					<c:set var="endPage" value="${pageInfo.pageNum + 5}" />
				</c:when>
				<c:otherwise>
					<c:set var="startPage" value="${pageInfo.pages - 9}" />
					<c:set var="endPage" value="${pageInfo.pages}" />
				</c:otherwise>
			</c:choose>

			<c:if test="${startPage < 1}">
				<c:set var="startPage" value="1" />
			</c:if>

			<c:forEach var="i" begin="${startPage}" end="${endPage}">
				<c:choose>
					<c:when test="${i == pageInfo.pageNum}">
						<span>${i}</span>
					</c:when>
					<c:otherwise>
						<a href="${pageContext.request.contextPath}/huser/sousuo?ye=${i}&ge=${huixian.geshu}&mouhu=${huixian.mouhu}">${i}</a>
					</c:otherwise>
				</c:choose>
			</c:forEach>
			第${pageInfo.pageNum}页/共${pageInfo.pages}页
			共${pageInfo.total}条数据 每页显示${pageInfo.pageSize}条
		</div>
	</div>
</div>
</body>
</html>